1. Field of the Invention
The present invention relates to programming languages. More specifically, the present invention relates to a method and an apparatus for using a templating language to produce a host language factory for a safe subset of a templated language.
2. Related Art
Templating languages are widely used to dynamically produce output in a host language, wherein the output combines elements of the host language with elements specific to the templating language. In particular, these templating languages are most often used for translating markup languages (languages that mark text with “tags” that describe attributes of contiguous snippets of code), but templating is not restricted to markup languages.
Templating languages also usually include an “expression language” used to express conditions, and sometimes to specify the relationship between inputs and dynamic content in the output. For example, Java Server Pages (JSPs) use Java as the expression language.
Some templating languages have a mechanism for determining whether a string is in a subset of a host language. For example, Document Type Definitions (DTDs) perform this function for eXtensible Markup Language (XML), and Database schemas can be used to validate SQL in this manner. However, these schemas typically do not do a good job of handling languages that embed other languages. For example, in a DTD, it is not possible to specify that the value of an attribute is a Uniform Resource Identifier (URI).
Schemas also only answer the question of whether a snippet of the language is valid in isolation, so schemas cannot express some checks to determine whether languages share identifiers.
Furthermore, schemas cannot distinguish between snippets of a language that must be subject to rigorous tests and snippets of language that come from a privileged source and only need to pass checks to ensure that they are well-formed.